package com.seven.service;

import jakarta.annotation.Resource;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class JdbcQueryService {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Tool(description = "查询数据库中所有的表")
    public List<Map<String, Object>> queryAllTables(){
        String sql = "SELECT TABLE_NAME , TABLE_COMMENT FROM information_schema.tables WHERE TABLE_SCHEMA = DATABASE()";
        return jdbcTemplate.queryForList(sql);
    }

    @Tool(description = "查询数据库中的表的数据")
    public List<Map<String, Object>> queryTable(@ToolParam(description = "表名") String tableName){
        String sql = "SELECT * FROM " + tableName;
        return jdbcTemplate.queryForList(sql);
    }
}
